import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import createVitePlugins from './vite/plugins'

//vite文档: https://vitejs.dev/config/
export default defineConfig(({ mode, command }) =>{
    //comman用于判断生产、开发模式：https://cn.vitejs.dev/config/#conditional-config
    return {
        base: './',
        plugins: [
            createVitePlugins(command)
        ],
        resolve: {
            // https://cn.vitejs.dev/config/#resolve-alias
            alias: {// 设置别名
                '@': resolve(__dirname, 'src')
            },
            // https://cn.vitejs.dev/config/#resolve-extensions
            extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
        },
        css: {
            preprocessorOptions: {
                /*全局css变量*/
                less: {
                    javascriptEnabled: true,
                    additionalData: '@import "./src/assets/style/variables.module.less";',
                },
            },
        },
        //启动端口、代理
        server: {
          port: 9999,
          host: true,
          open: false,
          proxy: {
              '/api': {
                  target: '',
                  changeOrigin: true,
                  rewrite: (p) => p.replace(/^\/api/, '/api')
              },
              /*远程easy mock*/
              '/ezMock': {
                  target: 'http://212.64.101.118:7300/mock/62ce7ecb84de3500179d528f/v3p',
                  changeOrigin: true,
                  rewrite: (p) => p.replace(/^\/ezMock/, '')
              }
          }
        },
        // 打包配置
        build: {
            brotliSize: false,
            terserOptions: {
                //生产取除consolelog、debugger
                compress: {
                    drop_console: true,
                    // 默认是true
                    drop_debugger: true
                }
            }
        }
    }
})
